from functools import partial
import subprocess

subprocess.Popen = partial(subprocess.Popen, encoding='utf-8')

import execjs
import requests

# key_word = input('>>>: ').strip()
key_word = 'word'
url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
f = open('bdfy.js', 'r', encoding='utf-8')
js = execjs.compile(f.read())
sign = js.call('e', key_word)
print(sign)

headers = {
    'Acs-Token': '1661065382517_1661088192200_2P8jWaPOlCQhdl3in7uwH8qPENSsjJjqS9SVWJWmfwENtHxv05vjGqvzx8udsCHwaa8bpLG0BdTBBuJctXyVcCy7IdS6nFIXLrMFXkeZOM985y5DlU6XetHbg6i6ah60d4Gq9YQS6ZAjGSf0Pn9/PWtNOL5Igy8ixy/4R9/liwAzwReRspOFhyJxiIa/afPLrVg3cV0WUvWMRYcUBhaAYmwEJT61CKrTGyrcIoKKsKxpnwtk04obPcogtyWYiGdrrWKw1Md3GdZRDvhEOy6UZ/8vO/C8InHkd2/bAKBiI5YkKV23MBc+9FC8Lkmw1WKNHyiwXhCZv+0uvMgCgwQtuQ==',
    'Cookie': 'REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; HISTORY_SWITCH=1; BIDUPSID=7565343A515460CE5EEB41E30F5C7202; PSTM=1652844500; BAIDUID=827AC52345C427C500FB16C631E8BDCB:FG=1; APPGUIDE_10_0_2=1; H_WISE_SIDS=110085_127969_179350_180636_189755_190619_194085_194519_194529_196428_197711_199577_204907_206124_206704_207234_208721_209568_210306_210321_210733_211952_212296_212416_212869_212912_212967_213045_213080_213094_213158_213278_213350_213548_214094_214189_214205_214596_214641_215070_215175_215281_215330_215680_215728_215731_215825_215861_215892_215958_216307_216333_216343_216354_216369_216596_216646_216845_216914_216927_216942_216965_217184_217198_217210_217392_217409_217450_217503_217836_218018_218030_218185_218326_218359_218445_218540_218549_218597_218856_218952_218960_219067; BAIDUID_BFESS=827AC52345C427C500FB16C631E8BDCB:FG=1; ZFY=zoFMkiv9ToPZHidJ0omNPuZU8qzYZXb9z1lpa:Bq7eyU:C; H_WISE_SIDS_BFESS=110085_127969_179350_180636_189755_190619_194085_194519_194529_196428_197711_199577_204907_206124_206704_207234_208721_209568_210306_210321_210733_211952_212296_212416_212869_212912_212967_213045_213080_213094_213158_213278_213350_213548_214094_214189_214205_214596_214641_215070_215175_215281_215330_215680_215728_215731_215825_215861_215892_215958_216307_216333_216343_216354_216369_216596_216646_216845_216914_216927_216942_216965_217184_217198_217210_217392_217409_217450_217503_217836_218018_218030_218185_218326_218359_218445_218540_218549_218597_218856_218952_218960_219067; MCITY=-%3A; newlogin=1; BDUSS=80Ullib09LVnNpM3NycnY0dlM4RlpXWFdhVjBCRHJzZFpoS35DdlZLZGwyQ0pqRVFBQUFBJCQAAAAAAQAAAAEAAADPEwwkMbqrv8bOsDEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGVL-2JlS~tidG; BDUSS_BFESS=80Ullib09LVnNpM3NycnY0dlM4RlpXWFdhVjBCRHJzZFpoS35DdlZLZGwyQ0pqRVFBQUFBJCQAAAAAAQAAAAEAAADPEwwkMbqrv8bOsDEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGVL-2JlS~tidG; RT="z=1&dm=baidu.com&si=ikvrg5zxeh&ss=l6w0yvdd&sl=0&tt=0&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ul=1wh&hd=202"; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1658807251,1658985368,1660613024,1661038959; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1661038959; ___wk_scode_token=EGnlZSH1kBhRxCPFrfdI18qj7H7K%2B36OiCTJCLpa7xE%3D; H_PS_PSSID=36560_36625_37112_36885_34812_36917_37003_26350_37202; BA_HECTOR=8k810l200k0k81a52g23s1as1hg42mf17',
    'Referer': 'https://fanyi.baidu.com/?aldtype=16047',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
data = {
    'from': 'en',
    'to': 'zh',
    'query': key_word,
    'transtype': 'realtime',
    'simple_means_flag': '3',
    'sign': sign,
    'token': 'f0be58206895e31ac09cfc2469e257fd',
    'domain': 'common',
}
res = requests.post(url, headers=headers, data=data)
print(res.json())

